#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int m;
int x[15], y[15], k[30], p[50];
int ans = 0;
vector<vector<int>> ret;
vector<int> temp;
void func(int row, int col, int n) {
    if(n > m) {
        ans++;
        ret.push_back(temp);
        return;
    }
    for(int i = 1; i <= m; i++) {
        if(y[i] == 0 && x[row] == 0 && k[row + i] == 0 && p[row - i + 30] == 0) {
            y[i] = 1;
            x[row] = 1;
            k[row + i] = 1;
            p[row - i + 30] = 1;
            temp.push_back(i);
            func(row + 1, col, n + 1);
            y[i] = 0;
            x[row] = 0;
            k[row + i] = 0;
            p[row - i + 30] = 0;
            temp.pop_back();
        }
    }
    return;
}
int main() {
    cin >> m;
    func(1, 1, 1);
   
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < ret[i].size(); j++) {
            cout << ret[i][j] << " ";
        }
        cout << endl;
    }
    cout << ans << endl;
    return 0;
} 